﻿
@inject AuthenticationStateProvider AuthenticationStateProvider
@inject UserManager<IdentityUser> UserManager

<AuthorizeView>
    <Authorized>

        <a href="Identity/Account/Manage"> @UserId</a>，您好！

        <form method="post" action="Identity/Account/LogOut">
            <button type="submit" class="nav-link btn btn-link">退出登录</button>
        </form>
    </Authorized>
    <NotAuthorized>
        <a href="Identity/Account/Login">登录</a>
    </NotAuthorized>
</AuthorizeView>
@code{
    string UserId { get; set; }

    protected override async Task OnInitializedAsync()
    {
        var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
        var User = authState.User;
        UserId = UserManager.GetUserId(User);
    }
}
